package jdo.editors;

import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.contentassist.ContentAssistant;
import org.eclipse.jface.text.contentassist.IContentAssistant;
import org.eclipse.jface.text.formatter.ContentFormatter;
import org.eclipse.jface.text.formatter.IContentFormatter;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;

public class JDOConfiguration extends SourceViewerConfiguration {

	private JDOContentAssistent assistent;
	/**
	 * 演示协调器
	 */
	@Override
	public IPresentationReconciler getPresentationReconciler(
			ISourceViewer sourceViewer) {
		PresentationReconciler reconciler = new PresentationReconciler();
		DefaultDamagerRepairer dr = new DefaultDamagerRepairer(
				new JDOPartitionScanner());
		reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
		reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
		return reconciler;
	}

	/**
	 * 设置格式化
	 */
	@Override
	public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
		ContentFormatter formatter = new ContentFormatter();
		formatter.setFormattingStrategy(new JDOFormattingStrategy(),
				IDocument.DEFAULT_CONTENT_TYPE);
		formatter.enablePartitionAwareFormatting(true);
		return formatter;
	}

	/**
	 * 设置自动提示.
	 */
	@Override
	public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
		ContentAssistant contentAssistent = new ContentAssistant();
		assistent = new JDOContentAssistent();
		contentAssistent.setContentAssistProcessor(assistent,
				IDocument.DEFAULT_CONTENT_TYPE);
		contentAssistent.enableAutoActivation(true);
		contentAssistent.setAutoActivationDelay(200);
		return contentAssistent;
	}
	
}
